package com.haixiaoke.saas.repository.service.impl;


import cn.hutool.core.util.StrUtil;
import com.haixiaoke.saas.repository.mapper.HotAttractionsMapper;
import com.haixiaoke.saas.repository.pojo.HotAttractions;
import com.haixiaoke.saas.repository.service.IHotAttractionsService;
import com.haixiaoke.saas.repository.util.Tree.Node;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.haixiaoke.saas.repository.mapper.HotAttractionsMapper;
import com.haixiaoke.saas.repository.service.IHotAttractionsService;

import java.util.Date;
import java.util.List;

/**
 * 热门景点Service业务层处理
 *
 * @author qixi
 * @date 2023-04-06
 */
@Service
@RequiredArgsConstructor
public class HotAttractionsServiceImpl implements IHotAttractionsService {

    private final HotAttractionsMapper hotAttractionsMapper;

    /**
     * 查询热门景点
     *
     * @param attractionsId 热门景点主键
     * @return 热门景点
     */
    @Override
    public HotAttractions selectHotAttractionsByAttractionsId(Long attractionsId) {
        return hotAttractionsMapper.selectHotAttractionsByAttractionsId(attractionsId);
    }

    /**
     * 查询热门景点列表
     *
     * @param hotAttractions 热门景点
     * @return 热门景点
     */
    @Override
    public List<HotAttractions> selectHotAttractionsList(HotAttractions hotAttractions) {
        return hotAttractionsMapper.selectHotAttractionsList(hotAttractions);
    }

    /**
     * 新增热门景点
     *
     * @param hotAttractions 热门景点
     * @return 结果
     */
    @Override
    public int insertHotAttractions(HotAttractions hotAttractions) {
        hotAttractions.setCreateTime(new Date());
        return hotAttractionsMapper.insertHotAttractions(hotAttractions);
    }

    /**
     * 修改热门景点
     *
     * @param hotAttractions 热门景点
     * @return 结果
     */
    @Override
    public int updateHotAttractions(HotAttractions hotAttractions) {
        hotAttractions.setUpdateTime(new Date());
        return hotAttractionsMapper.updateHotAttractions(hotAttractions);
    }

    /**
     * 批量删除热门景点
     *
     * @param attractionsIds 需要删除的热门景点主键
     * @return 结果
     */
    @Override
    public int deleteHotAttractionsByAttractionsIds(Long[] attractionsIds) {
        return hotAttractionsMapper.deleteHotAttractionsByAttractionsIds(attractionsIds);
    }

    /**
     * 删除热门景点信息
     *
     * @param attractionsId 热门景点主键
     * @return 结果
     */
    @Override
    public int deleteHotAttractionsByAttractionsId(Long attractionsId) {
        return hotAttractionsMapper.deleteHotAttractionsByAttractionsId(attractionsId);
    }

    @Override
    public boolean checkCoordinatesUnique(HotAttractions hotAttractions) {
        return hotAttractionsMapper.checkCoordinatesUnique(hotAttractions) == 0;
    }

    @Override
    public List<HotAttractions> selectHotAttractionsByAttractionsIdIn(List<Long> attractionsIdList) {
        return hotAttractionsMapper.selectHotAttractionsByAttractionsIdIn(attractionsIdList);
    }

    @Override
    public String selectHotAttractionFullNamesByIdIn(List<Long> attractionsIdList) {
        StringBuilder hotAttractionFullNames = new StringBuilder();

        //拼接景区全名
        List<HotAttractions> hotAttractions = hotAttractionsMapper.selectHotAttractionsByAttractionsIdIn(attractionsIdList);
        if (!hotAttractions.isEmpty()) {
            for (HotAttractions hotAttraction : hotAttractions) {
                String provinceName = hotAttraction.getProvinceName();
                String cityName = hotAttraction.getCityName();
                String attractionsName = hotAttraction.getAttractionsName();
                hotAttractionFullNames.append(provinceName).append(cityName).append(attractionsName).append(",");
            }
        }
        if (StrUtil.isNotBlank(hotAttractionFullNames)) {
            hotAttractionFullNames.deleteCharAt(hotAttractionFullNames.lastIndexOf(","));
        }
        return hotAttractionFullNames.toString();
    }

    @Override
    public List<Node> selectComboListByCityId(Long cityId) {
        return hotAttractionsMapper.selectComboListByCityId(cityId);
    }


}
